package com.teaching.Controller;

import com.alibaba.fastjson.JSONObject;
import com.teaching.Dao.*;
import com.teaching.Enity.Course;
import com.teaching.Enity.ScoreView;
import com.teaching.Enity.Student;
import com.teaching.Enity.Teacher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;

@RestController
public class SelectController {

    @PostMapping(value = "/getTeacher",produces = "application/json;charset=UTF-8")     //获取教师个人信息的接口传入参数t_id
    public Teacher getTeacher(@RequestBody JSONObject jsonObject) throws IOException {
        int t_id = jsonObject.getInteger("t_id");
        TeacherDaoAchieve teacherDaoAchieve = new TeacherDaoAchieve();
        List<Teacher> teacherList = teacherDaoAchieve.findTeacher(t_id);
        return teacherList.get(0);
    }

    @PostMapping(value = "/getStudent",produces = "application/json;charset=UTF-8")     //获取学生个人信息的接口传入参数s_id
    public Student getStudent(@RequestBody JSONObject jsonObject) throws IOException{
        int s_id = jsonObject.getInteger("s_id");
        StudentDaoAchieve studentDaoAchieve = new StudentDaoAchieve();
        List<Student> studentList = studentDaoAchieve.findStudent(s_id);
        return studentList.get(0);
    }

    @GetMapping(value = "/getAllCourse")                                                //获取全部课程信息
    public List<Course> getAllCourse() throws IOException{
        CourseDaoAchieve courseDaoAchieve = new CourseDaoAchieve();
        List<Course> courseList = courseDaoAchieve.findAllCourse();
        return courseList;
    }

    @PostMapping(value = "/getTeacherCourse",produces = "application/json;charset=UTF-8") //获取老师所教课程的信息传入参数t_id
    public List<Course> getTeacherCourse(@RequestBody JSONObject jsonObject) throws IOException{
        int t_id = jsonObject.getInteger("t_id");
        CourseDaoAchieve courseDaoAchieve = new CourseDaoAchieve();
        List<Course> courseList = courseDaoAchieve.findTeacherCourse(t_id);
        return courseList;
    }

    @PostMapping(value = "/getCourseStudent",produces = "application/json;charset=UTF-8")  //获取所教课程的学生信息传入参数c_id
    public List<Student> getCourseStudent(@RequestBody JSONObject jsonObject) throws IOException{
        int c_id = jsonObject.getInteger("c_id");
        StudentDaoAchieve studentDaoAchieve = new StudentDaoAchieve();
        List<Student> studentList = studentDaoAchieve.findLearnStudent(c_id);
        return studentList;
    }

    @PostMapping(value = "/getStudentCourse",produces = "application/json;charset=UTF-8")  //获取学生选的课
    public List<Course> getStudentCourse(@RequestBody JSONObject jsonObject) throws IOException{
        int s_id = jsonObject.getInteger("s_id");
        CourseDaoAchieve courseDaoAchieve = new CourseDaoAchieve();
        List<Course> courseList = courseDaoAchieve.findStudentCourse(s_id);
        return courseList;
    }

    @PostMapping(value = "getScore",produces = "application/json;charset=UTF-8")//学生获取成绩
    public List<ScoreView> getScore(@RequestBody JSONObject jsonObject) throws IOException{
        int s_id = jsonObject.getInteger("s_id");
        ScoreViewDaoAchieve scoreViewDaoAchieve = new ScoreViewDaoAchieve();
        List<ScoreView> scoreViewList = scoreViewDaoAchieve.GetScore(s_id);
        return scoreViewList;
    }
}
